function P = fp_mult(A,B)
    sgn = A(1) | B(1);
    
    A_m = [1 A(10:32)];
    B_m = [1 B(10:32)];
    M = mult_helper(pp(A_m,B_m));
    MSB = M(1:2);
    shift_l_times = 0;
    if ~MSB(1)&&~MSB(2) 
       shift_l_times = find(M,1,'first')-2;
       M = M(1+shift_l_times-1:23+shift_l_times-1);
    elseif ~MSB(1)&&MSB(2) 
       shift_l_times = find(M,1,'first')-1;
       M = M(1+shift_l_times-1:23+shift_l_times-1);
    else
       M = M(2:24);
    end
    
    A_e = A(2:9);
    B_e = B(2:9);
    
    a_e = binint2dec(A_e)-127;
    b_e = binint2dec(B_e)-127;
    e = a_e+b_e+shift_l_times+127;
        
    E = zeros(1,8);
    E_t = dec2bin(e)-48;
    E(8-length(E_t)+1:8) = E_t;
    
    P = [sgn E M];
end

function Z = pp(A, B)
    len_a = length(A);
    len_b = length(B);
    Z = zeros(len_b, len_a+len_b-1);
    for i = 1:len_a,
        Z(len_a-i+1,:) = [zeros(1,i-1) A(i)*B zeros(1,len_a-i)];
    end
end

function T = mult_helper(Z)
    height = size(Z,1);
    T = zeros(1,length(Z));
    for i = 1:height,
        T = T+Z(i,:);
        C = 1;
        while(sum(C)>0)
            C = T==2;
            C_LS = [C(2:end) 0];
            T(T==2) = 0;
            T = T + C_LS;
        end
    end
end

function [Z,co] = add(A,B)
    len = length(A);
    Z = zeros(1,len);
    ci = 0;
    for i = len:-1:1,
        a = A(i);
        b = B(i);
        [s,ci] = FA(a,b,ci);
        Z(i) = s;
    end
    co = ci;
end

function [s,co] = FA(a,b,ci)
    t = xor(a,b);
    s = xor(t,ci); 
    co = (a&&b)||(t&&ci);
end

function [t] = binint2dec(T)
    len_t = length(T);
    t = 0;
    for i = len_t:-1:1,
        t = t + T(i)*2^(len_t-i);
    end 
end

function []=prnt_mantissa(B, h)
    for i=1:length(B),
        if (h == 1 && i == 2) || (h == 2 && i == 3) || (h == 0 && i == 24) || (h == 1 && i == 25) || (h == 2 && i == 26)
            fprintf(' '); 
        end
        fprintf('%d',B(i)); 
    end
    fprintf('\n');
end